package com.fhz.day014;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
import android.widget.RemoteViews;

public class MyService extends Service {
    private static final String TAG = "feng";
    public MyService() {
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.i(TAG, "onCreate: ");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i(TAG, "onStartCommand: ");

        Notification.Builder builder = new Notification.Builder(this);

        builder.setSmallIcon(R.mipmap.ic_launcher);
        builder.setContentText("内容");
        builder.setContentTitle("标题");

        Intent intent1 = new Intent(this, MainActivity.class);
        PendingIntent activity = PendingIntent.getActivity(this, 100, intent1, 0);


        //定义一个remoteView; 实现一个按钮的点击.
        RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.remote_layout);
        //根据id修改内容
        remoteViews.setTextViewText(R.id.title,"你好");
        //指定组件跳转
        remoteViews.setOnClickPendingIntent(R.id.image,activity);


        builder.setCustomContentView(remoteViews);
//        builder.setContentIntent(activity);
        Notification build = builder.build();
        startForeground(1,build);

        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "onDestroy: ");
        stopForeground(true);
    }


    class MyBinder extends Binder {
        public void callShow(){
            show();
        }
        public void callShow1(){
            show1();
        }
    }


    @Override
    public IBinder onBind(Intent intent) {
        Log.i(TAG, "onBind: ");
        return new MyBinder();
    }

    public void show(){
        Log.i(TAG, "show: ");
        //1m 10m  什么时候停止服务合适?

    }

    public void show1(){
        Log.i(TAG, "show2: ");
    }
}